/**
 * 
 */
package travibot.ui.gui.forms.providers.content;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import travibot.model.Building;
import travibot.model.Structure;
import travibot.model.Village;


/**
 * @author tajzivit
 *
 */
public class BuildingsContentProvider implements ITreeContentProvider {

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
     */
    public Object[] getChildren(Object obj) {

        List<Structure> result = new ArrayList<Structure>();
        
        if(!(obj instanceof Village))
            return new Object[0];

        Village v = (Village)obj;
        
        if(v.isInitialized()){
            List<Structure> structures = v.getStructures();        
            if(structures == null)
                return new Object[0];
            
            Iterator<Structure> buildingIterator = structures.iterator();
            while(buildingIterator.hasNext()){
                
                Structure s = buildingIterator.next();
                
                if(s instanceof Building)
                    result.add(s);
            }
        }
            
        return result.toArray();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
     */
    public Object getParent(Object arg0) {

        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
     */
    public boolean hasChildren(Object arg0) {

        // TODO Auto-generated method stub
        return false;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
     */
    public Object[] getElements(Object arg0) {

        return getChildren(arg0);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
     */
    public void dispose() {

        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    public void inputChanged(Viewer arg0, Object arg1, Object arg2) {

        // TODO Auto-generated method stub

    }

}
